package com.deer.im.message;

import java.util.HashMap;
import java.util.Map;

import org.springframework.http.MediaType;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;

/**
 * 字节消息体
 * 
 * @author deer
 * @date 2021年11月30日
 */
public class ByteMessage implements Message<byte[]> {
	/**
	 * 载荷
	 */
	private byte[] payload;

	/**
	 * Headers
	 */
	private MessageHeaders messageHeaders;

	public ByteMessage(byte[] payload) {
		Map<String, Object> m = new HashMap<>();
		m.put("contentType", MediaType.APPLICATION_OCTET_STREAM_VALUE);
		this.messageHeaders = new MessageHeaders(m);
		this.payload = payload;
	}

	public ByteMessage(byte[] payload, MessageHeaders messageHeaders) {
		this.payload = payload;
		this.messageHeaders = messageHeaders;
	}

	@Override
	public byte[] getPayload() {
		return payload;
	}

	@Override
	public MessageHeaders getHeaders() {
		return messageHeaders;
	}

	public static MessageHeaders byteHeaders() {
		Map<String, Object> m = new HashMap<>();
		m.put(MessageHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
		return new MessageHeaders(m);
	}

}
